package com.ray.ba.starter.security.jwt.security;


import com.ray.ba.starter.security.jwt.constant.SecurityConstant;
import com.ray.ba.starter.security.jwt.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * JwtUserDetailsServiceImpl
 *
 * @author ray
 * @date 2020/2/26
 */
@Slf4j
public class JwtUserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        JwtUser userDetail = (JwtUser) SecurityUtils.getUserDetails();
        return new JwtUser(userDetail.getId(), userDetail.getUsername(), SecurityConstant.NO_PASSWORD_ENCODED, userDetail.getEmail(), userDetail.getAuthorities());
    }

}
